home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- +
- + LEDA 2.1.1 11-15-1991
- +
- +
- + dp_hashing.h
- +
- +
- + Copyright (c) 1991 by Max-Planck-Institut fuer Informatik
- + Im Stadtwald, 6600 Saarbruecken, FRG
- + All rights reserved.
- +
- *******************************************************************************/
-
-
-
-
-
- //------------------------------------------------------------------------------
- // Dynamic Perfect Hashing
- //
- // Michael Wenzel ( 1989/90 )
- //------------------------------------------------------------------------------
-
-
- #ifndef DPHASHINGH
- #define DPHASHINGH
-
- #include <LEDA/basic.h>
-
-
- // ---------------------------------------------------------------
- // declarations
- // ---------------------------------------------------------------
-
-
- class headertable;
- class subtable;
- class dphash;
-
- typedef headertable* htp;
- typedef subtable* stp;
-
- #define EMPTY (ent(2147483648))
- #define maxuni 2147483647
- // #define maxprim 2147483659
- // aber kleiner wegen random-Funktion
- #define maxprim 2147483647
- #define wursechs 2.44948974278
-
- // --------------------------------------------------------------
- // class declarations
- // --------------------------------------------------------------
-
- // --------------------------------------------------------------
- // class headertable
- //
- // Items werden auf Headertables gehasht,
- // die sie dann injektiv auf Subtables verteilen
-
- class headertable {
-
- unsigned kj; // Multiplikator
- int wj; // Anzahl Elemente in Tafel
- int mj; // max. Anzahl Elemente
- stp tj; // Startpunkt der Subtables
-
- friend class b_dict;
- friend class dphash;
- friend class subtable;
-
- stp lookup(ent );
-
- bool insert(ent ,ent ,stp& ,int& ,bool& ,stp ,stp );
- int dinsert(ent ,ent ,stp ,stp& ,stp& );
-
- bool del(ent ,stp ,stp );
- int give_elements(stp& ,stp ,stp );
-
-
- headertable()
- {
- kj = wj = mj=0;
- tj=0;
- }
-
- OPERATOR_NEW(4);
- OPERATOR_DEL(4);
-
- };
-
- // --------------------------------------------------------------
- // class subtable
- //
- // Jedes Subtableelement ist leer,
- // oder von der Headertable wird genau ein Element
- // auf eine Position gehasht
-
- class subtable {
-
- ent ke;
- ent inf;
-
- friend class b_dict;
- friend class dphash;
- friend class headertable;
-
- void set_s(ent a,ent b)
- {
- ke=a; inf=b; }
-
- void clear()
- {
- ke=EMPTY; inf=0; }
-
- subtable()
- {
- ke=EMPTY; inf=0; }
-
- subtable(ent a ,ent b )
- {
- ke=a; inf=b; }
-
- subtable(subtable& s)
- {
- ke=s.ke;
- inf=s.inf; }
-
- subtable& operator=(subtable& s)
- {
- ke=s.ke;
- inf=s.inf;
- return *this; }
-
- OPERATOR_NEW(2);
- OPERATOR_DEL(2);
-
- public:
-
- ent key() { return ke; }
-
- ent info() { return inf; }
-
- };
-
- // ------------------------------------------------------------------
- // class dphash
- //
- // alle Informationen fuer das Dictionary
- // Elemente werden auf Headertables gehasht,
- // die dann die Elemente weitergeben
- // Der Platzverbrauch der Headertables wird kontrolliert
-
-
- class dphash {
-
- htp* htablep; // Feld von Zeigern auf Headertables
- // leere Headertables werden nicht angelegt
-
- unsigned k; // Verteilungsfunktion (k*x)%p%sM
-
- int n; // Anzahl Elemente im Dictionary
-
- int M; // Anzahl Elemente, die momentan bzgl.
- // Platzverbrauch mit Wahrscheinlichkeit >= 0.5
- // abgespeichert werden koennen ( ohne Rehash )
-
- int sM; // Anzahl Headertables
-
- int bed; // Kontrolle des Platzverbrauchs
-
- stp anf,wo,ende; // zur Speicherverwaltung beim Rehash
-
-
-
- stp rehash_all(ent ,ent );
-
-
- virtual void clear_key(ent&) {}
- virtual void clear_inf(ent&) {}
-
- virtual void copy_key(ent&) {}
- virtual void copy_inf(ent&) {}
-
- public:
-
- ent key(stp it)
- { return ( it ) ? it->key() : 0 ; }
-
- ent& info(stp it)
- { if (!it) error_handler(1,"dp_item gleich nil");
- return it->inf; }
-
- stp insert(ent ,ent );
- void del(ent );
-
- int member(ent );
- stp lookup(ent );
-
- stp change_inf(ent ,ent );
-
- int size()
- { return n; }
-
- void clear();
-
-
- dphash();
- dphash(int ,ent* ,ent* );
- ~dphash();
-
-
- friend class b_dict;
-
- };
-
- #endif DPHASHINGH
-